from django.contrib import admin
from .models import Post, Category, Tag , Friend , UserExtension


class PostAdmin(admin.ModelAdmin):
    list_display = ['title', 'created_time', 'modified_time', 'category', 'author']
    fields = ['title', 'body', 'excerpt', 'pic' ,'category', 'tags','created_time']
    
    #自动设置文章作者为当前用户
    def save_model(self, request, obj, form, change):
        obj.author = request.user
        super().save_model(request, obj, form, change)

class CommentAdmin(admin.ModelAdmin):
    list_display = ['name', 'email', 'url', 'post', 'created_time']
    fields = ['name', 'email', 'url', 'text', 'post']

# 把新增的 Postadmin 也注册进来
# admin.site.register(PostAdmin)
admin.site.register(Post,PostAdmin)
admin.site.register(Category)
admin.site.register(Tag)
admin.site.register(Friend)
admin.site.register(UserExtension)